package osk.biz;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


public class PlaceDAO extends DataAccessObject{
	String PLACE_ADD ="";
	String PLACE_UPDATE="";
	String PLACE_DELETE="";
	String PLACE_GET="select * from place where category_id = ?, cost <= ?, adress like ? ";
	String PLACE_GET_LIST="select * from place where category_id = ? and cost <= ? and adress like concat('%',?,'%') ";
	String PLACE_GET_BY_ID="";
	public PlaceDAO(){
		super();
	}
	
	public void addPlace(PlaceDTO dto){
		try {
			stmt = conn.prepareStatement(PLACE_ADD);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void updatePlace(PlaceDTO dto){
		try {
			stmt = conn.prepareStatement(PLACE_UPDATE);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void deletePlace(PlaceDTO dto){
		try {
			stmt = conn.prepareStatement(PLACE_DELETE);;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public List<PlaceDTO> getPlaceList(PlaceDTO dto){
		List<PlaceDTO> placeList = new ArrayList<PlaceDTO>();
		try {
			stmt = conn.prepareStatement(PLACE_GET_LIST);
			stmt.setInt(1,dto.getCategory());
			stmt.setInt(2,dto.getCost());
			stmt.setString(3, dto.getAdress());
			rs = stmt.executeQuery();
			
			while(rs.next()){
				PlaceDTO place = new PlaceDTO();
				place.setId(rs.getInt("place_id"));
				place.setAdress(rs.getString("adress"));
				place.setAssociated_link(rs.getString("associated_link"));
				place.setCategory(rs.getInt("category_id"));
				place.setCost(rs.getInt("cost"));
				place.setExplanation(rs.getString("explanation"));
				place.setImageURI(rs.getString("image"));
				place.setPhone(rs.getString("phone_num"));
				place.setName(rs.getString("name"));
				place.setWingBus_link(rs.getString("wingbus_link"));
				
				placeList.add(place);
			}			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			JDBCUtil.close(rs, stmt, conn);
		}
		return placeList;
	}
	public PlaceDTO getOnePlaceByID(PlaceDTO dto){
		try {
			stmt = conn.prepareStatement(PLACE_GET_BY_ID);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return dto;
	}
}
